<template>

  <!--  <div>-->
  <!--    关键字： <el-input v-model="form.quan" placeholder="请输入手机号/ID"></el-input>-->
  <!--  </div>-->
  <!--  关键字： <el-input v-model="form.quan" placeholder="请输入手机号/ID"></el-input>&ndash;&gt;-->
  <el-container class="home-container">
    <el-header><!-- 头部区 -->
      <div>
        <span>智能快递柜后台管理系统</span>
      </div>
      <el-menu
          :default-active="activeIndex"
          class="el-menu-demo"
          mode="horizontal"
          @select="handleSelect"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          id="indexMenu">
        <el-menu-item index="1" @click="shouye">首页</el-menu-item>
        <el-menu-item index="2" @click="huiyuan">会员</el-menu-item>
        <el-menu-item index="3" @click="goToMachine">柜机</el-menu-item>
        <el-menu-item index="4" @click="baoguo">包裹</el-menu-item>
        <el-menu-item index="5" @click="tiaozhuan">财务</el-menu-item>
        <el-menu-item index="6" @click="other">其他</el-menu-item>
      </el-menu>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="210px" hight="100%">
        <el-menu
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>财务管理</span>
            </template>
            <el-menu-item-group>
              <!--              <template slot="title">分组一</template>-->
              <el-menu-item index="1-1" @click="zhanghu">账户信息</el-menu-item>
              <el-menu-item index="1-2" @click="zhifu">支付记录</el-menu-item>
              <el-menu-item index="1-3" @click="chongzhiji">充值记录</el-menu-item>
              <el-menu-item index="1-4" >汇率管理</el-menu-item>

              <!--              <el-menu-item index="1-2">选项2</el-menu-item>-->
            </el-menu-item-group>
            <!--            <el-menu-item-group title="分组2">-->
            <!--              <el-menu-item index="1-3">支付记录</el-menu-item>-->
            <!--            </el-menu-item-group>-->
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>意见反馈</span>
            </template>
            <el-menu-item-group>
              <!--              <template slot="title">分组一</template>-->
              <el-menu-item index="1-1" @click="yijian">意见反馈</el-menu-item>
              <el-menu-item index="1-2" >反馈详情-未处理</el-menu-item>
              <el-menu-item index="1-3" >反馈详情-跟进中</el-menu-item>
              <el-menu-item index="1-4" >反馈详情-已完结</el-menu-item>
              <el-menu-item index="1-4" >回复反馈</el-menu-item>

            </el-menu-item-group>
            <!--            <el-menu-item-group title="分组2">-->
            <!--              <el-menu-item index="1-3">支付记录</el-menu-item>-->
            <!--            </el-menu-item-group>-->
          </el-submenu>

          <el-menu-item index="4">
            <i class="el-icon-setting"></i>
            <span slot="title">导航四</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <!--<span>aaa</span>-->
<!--        <div>-->
<!--          <input v-model="form.id" placeholder="请输入手机号/交易号" class="responsive-width">&nbsp;&nbsp;&nbsp;-->
<!--          <el-button type="primary" @click="sousuo">高级搜索</el-button>-->
<!--          <el-button type="primary" @click="chongzhi">重置</el-button>-->

<!--        </div>-->
        <div>
          <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择开始日期" v-model="form.beginTime"></el-date-picker>
          <el-col class="line" :span="2">-</el-col>
          <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择结束日期" v-model="form.endTime"></el-date-picker>
          <el-button type="primary" @click="sousuo">高级搜索</el-button>
                    <el-button type="primary" @click="chongzhi">重置</el-button>
        </div>

        <div >
          <span style="float: left;font-weight: bold">汇率管理</span><br><br>

          <template>
            <el-table  :data="this.guiList" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="ID" align="center" prop="id" >
                <template slot-scope="scope">
                  <span style="color: blue; text-decoration: underline;" @click="hui(scope.row)">{{scope.row.id}}</span>
                </template>
              </el-table-column>
              <el-table-column label="系统计算汇率" align="center" prop="erm">
                <template slot-scope="scope">
                    <span>{{scope.row.erm}}</span>
                </template>
              </el-table-column>
              <el-table-column label="当日基准汇率" align="center" prop="referenceRate">
                <template slot-scope="scope">
                  <span>{{scope.row.referenceRate}}</span>
                </template>
              </el-table-column>
              <el-table-column label="有效时间" align="center" prop="referenceRate">
                <template slot-scope="scope">
                  <span>{{scope.row.beginTime|format('yyyy-MM-dd hh:mm:ss')}}至{{scope.row.endTime|format('yyyy-MM-dd hh:mm:ss')}}</span>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                  <span>{{scope.row.status==1?'生效中':'已失效'}}</span>
                </template>
              </el-table-column>
              <el-table-column label="备注" align="center" prop="bz">
                <template slot-scope="scope">
                  <span>{{scope.row.bz}}</span>
                </template>
              </el-table-column>


            </el-table>
          </template>
        </div>

        <div>
          <el-dialog
              title="提示"
              :visible.sync="dialogVisible"
              width="30%"
              :before-close="handleClose">
            <span>你确定要将{{this.phone}}账户锁定吗？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
            </span>
          </el-dialog>
        </div>

        <div>
          <el-dialog
              title="提示"
              :visible.sync="dialogVisible2"
              width="30%"
              :before-close="handleClose">
            <span>你确定要将{{this.phone}}账户解锁吗？</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible2 = false">取 消</el-button>
            <el-button type="primary" @click="submit2">确 定</el-button>
            </span>
          </el-dialog>
        </div>

        <div>
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="pageNumber"
              :page-sizes="[2, 4, 6, 8]"
              :page-size=pageSize
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
          </el-pagination>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import index from "vue-lazyload";
import axios from "axios";
export default {
  filters:{
    format(value,arg){
      function dateFormat(date, format) {
        if (typeof date === "string") {
          var mts = date.match(/(\/Date\((\d+)\)\/)/);
          if (mts && mts.length >= 3) {
            date = parseInt(mts[2]);
          }
        }
        date = new Date(date);
        if (!date || date.toUTCString() == "Invalid Date") {
          return "";
        }
        var map = {
          "M": date.getMonth() + 1, //月份
          "d": date.getDate(), //日
          "h": date.getHours(), //小时
          "m": date.getMinutes(), //分
          "s": date.getSeconds(), //秒
          "q": Math.floor((date.getMonth() + 3) / 3), //季度
          "S": date.getMilliseconds() //毫秒
        };
        format = format.replace(/([yMdhmsqS])+/g, function (all, t) {
          var v = map[t];
          if (v !== undefined) {
            if (all.length > 1) {
              v = '0' + v;
              v = v.substr(v.length - 2);
            }
            return v;
          } else if (t === 'y') {
            return (date.getFullYear() + '').substr(4 - all.length);
          }
          return all;
        });
        return format;
      }

      return dateFormat(value,arg);

    }
  },
  data() {
    return {
      activeIndex: '5',
      tableData: [{
      }],
      guiList: [{}],
      pageNumber: 1,
      pageSize: 2,
      total: 0,
      multipleSelection: [],
      form:{
        id:'',
        beginTime: '',
        endTime: '',
      },
      dialogVisible:false,
      dialogVisible2:false,
      idd:'',
      phone:'',
    };
  },
  methods: {
    baoguo(){
      this.$router.push(
          {path: "/OutPackage"}
      )
    },
    tiaozhuan(){
      this.$router.push({
        path:'/zhanghuPage.vue'
      })
    },
    other(){
      this.$router.push(
          {path: "/otherView"}
      )
    },
    huiyuan(){
      this.$router.push(
          {path: "/expressList"}
      )
    },
    yijian(){
      this.$router.push({
        path:'/feebackPage'
      })
    },
    huilv(){
      this.$router.push({
        path:'/huilvPage'
      })
    },
    chongzhiji(){
      this.$router.push({
        path:'/chongZhiPage'
      })
    },

    zhifu(){
      this.$router.push({
        path:'/zhifuPage'
      })
    },
    hui(row){
      this.$router.push(
          {path: "/huiXiangPage",

            query: {
              id: row
            },
          })
    },
    shouji(row){
      this.$router.push(
          {path: "/xiangPage",

            query: {
              id: row.phone,
              status:row.type,
            },
          })
    },

    chongxiang(row){
      this.$router.push(
          {path: "/chongXiangPage",
            query: {
              id: row.id,
              status:row.status,
            },
          })
    },
    handleClose(){
      this.dialogVisible=false;
      this.dialogVisible2=false;
    },
    zhanghu(){
      this.$router.push({
        path:'/zhanghuPage'
      })
    },
    submit2(){
      axios.get('http://localhost:8876/account/updatestatus2?id='+this.idd).then(response=>{
        console.log("==============="+response.data)
        if (response.data==1){
          this.$message({
            message: '解锁成功',
            type: 'success'
          });
          this.dialogVisible2=false;
          this.init();
        }else {
          this.$message({
            message: '解锁失败',
            type: 'error'
          });
          this.init();
        }
      });
    },
    submit(){
      axios.get('http://localhost:8876/account/updatestatus1?id='+this.idd).then(response=>{
        console.log("==============="+response.data)
        if (response.data==1){
          this.$message({
            message: '锁定成功',
            type: 'success'
          });
          this.dialogVisible=false;
          this.init();
        }else {
          this.$message({
            message: '锁定失败',
            type: 'error'
          });
          this.init();
        }
      });
    },
    dianji2(row){
      this.dialogVisible2=true;
      console.log("]]]]]]]]]]]]]]]"+row.id);
      this.idd=row.id;
      this.phone=row.phone;
    },
    dianji(row){
      this.dialogVisible=true;
      console.log("]]]]]]]]]]]]]]]"+row.id);
      this.idd=row.id;
      this.phone=row.phone;
    },
    chongzhi(){
      this.form={id:'',
      beginTime:'',
      endTime:''
      };
    },
    sousuo(){
      this.init();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize=val;
      this.init();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNumber=val;
      this.init();
    },
    shouye(){
      this.$router.push({
        path:'/'
      })
    },
    goToMachine(){
      this.$router.push(
          {path: "/machineHome"}
      )
    },

    index() {
      return index
    },
    handleSelect(key){
      console.log("-----------------"+key);
    },
    init() {
      axios.get('http://localhost:8876/exchange/list?pageNum='+this.pageNumber+'&pageSize='+this.pageSize+'&beginTime='+this.form.beginTime+'&endTime='+this.form.endTime).then(response=>{
        const aa=this.form.beginTime;
        console.log("=======+++++++============"+aa);
        this.guiList=response.data.list;
        this.total=response.data.total;
        console.log("===================="+this.guiList);
      });
    }
  },
  created() {
    // axios.get('http://localhost:8876/account/list').then(response=>{
    //   this.guiList=response.data;
    //   console.log("===================="+this.guiList);
    // });
    this.init();
  }
};
</script>

<style lang="less">
#app {
  margin-top: 0;
}

.responsive-width {
  width: 300px;
}
.home-container {
  height: 100%;
}

.el-header {
  background-color: #545c64;
  display: flex; //设置显示为flex布局
  justify-content: space-between; //设置为flex左右布局
  padding-left: 0; //左内边距为0（Logo贴左边）
  align-items: center; //元素上下居中（防止右边按钮贴上下边）
  color: #fff;
  font-size: 18px;

  > div {
    //内嵌的div样式
    display: flex;
    align-items: center; //Logo和文字上下居中
    span {
      width: 200px;
      margin-left: 10px; //文字左侧设置间距，防止与Logo紧贴
    }
  }
}

#indexMenu {
  width: 100%;
}

.el-menu {
  background-color: #545c64;
}

.el-aside {
  background-color: #545c64;
  scrollbar-width: none; /* firefox */
  -ms-overflow-style: none; /* IE 10+ */
  overflow-x: hidden;
  overflow-y: auto;
}

.el-main {
  background-color: #eaedf1;
}
</style>